<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>获取数字的最高位</title>
		<script>
			function zuigao(){
				var  num1=parseInt(document.getElementById("number").value);
				if(num1 < 0){
					alert("请输入一个正整数");
					return;
				}
				if( num1>0 && num1<10){
					document.getElementById("zg").value=num1;
				}
				while(num1 > 10){
					num1 = num1 / 10;
				}
				document.getElementById("zg").value = Math.trunc(num1);
			}
		</script>
	</head>
	<body>
		<form action="" style="padding-left: 330px; border:1px solid #f3f3f3">
					 <p>
						 <label for="number">
							 数字：
							 </label>
							 <input type="text" name="num" id="number">
						 
					 </p>
					 <p style="margin-left: -15px;">
					 		 最高位：
					 		<input type="text"  id="zg">
					 				
					 </p>
					 <input type="button" name="" id="" value="提交" onclick="zuigao()" style="margin-left: 90px;width: 60px;">
		</form>
	</body>
</html>